# -*- coding: utf-8 -*-
"""
@author: wyb
@date: 2023/12/18
@time: 20:15
@desc: Description
"""
from urllib import request
from urllib import parse
from fake_useragent import UserAgent

# 1  拼接URL地址
url = 'https://www.baidu.com/s?wd={}'
word = input('请输入搜索内容\n')
params = parse.quote(word)
full_url = url.format(params)

# 向URL发送请求
ua = UserAgent()
header = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'}
print(header)
req = request.Request(url=url, headers=header)
res = request.urlopen(req)
html = res.read().decode('utf-8')

filename = word + '.html'
with open(filename, 'w', encoding='utf-8') as f:
    f.write(html)
